package com.clouddot.baipai.presenter;


import com.clouddot.baipai.contract.INewsFragmentContract;
import com.clouddot.baipai.http.entity.response.getArcticByIdResponse;
import com.clouddot.baipai.http.entity.response.getArcticListResponse;

import org.wxy.sdk.base.impl.BasePresenterImpl;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class NewsFragmentPresenter extends BasePresenterImpl<INewsFragmentContract.IView, INewsFragmentContract.IModel> implements INewsFragmentContract.IPresenter {
    public NewsFragmentPresenter(INewsFragmentContract.IView view, INewsFragmentContract.IModel model) {
        super(view, model);
    }

    @Override
    public void getArcticList(String type, int pageindex, int pagesize) {
        Subscription subscription = mModel.getArcticList("QueryCmsPage", type, pageindex, pagesize)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getArcticListResponse>() {
                               @Override
                               public void call(getArcticListResponse response) {
                                   mView.success(1, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(1, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }

    @Override
    public void getArcticById(String id) {
        Subscription subscription = mModel.getArcticById("GetCmsById", id)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getArcticByIdResponse>() {
                               @Override
                               public void call(getArcticByIdResponse response) {
                                   mView.success(2, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(2, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }


}
